package com.virtualperson.controller;

import com.virtualperson.dto.StyleGenerationRequest;
import com.virtualperson.dto.StyleGenerationResponse;
import com.virtualperson.service.StyleGenerationService;
import com.virtualperson.util.StyleValidationUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/api/v1/style")
public class StyleGenerationController {

    private final StyleGenerationService styleGenerationService;

    public StyleGenerationController(StyleGenerationService styleGenerationService) {
        this.styleGenerationService = styleGenerationService;
    }

    /**
     * 生成风格化图片
     * @param request 风格化生成请求
     * @return 风格化生成响应
     */
    @PostMapping("/generate")
    public StyleGenerationResponse generateStyleImage(@RequestBody StyleGenerationRequest request) {
        log.info("收到风格化生成请求: model={}, imageUrl={}, styleIndex={}", 
            request.getModel(), 
            request.getInput().getImageUrl(),
            request.getInput().getStyleIndex());
        
        // 验证请求参数
        StyleValidationUtil.validateAndSetDefaults(request);
        
        // 生成图片
        StyleGenerationResponse response = styleGenerationService.generateStyleImage(request);
        log.info("风格化生成任务已创建: taskId={}, requestId={}", 
            response.getOutput().getTaskId(), 
            response.getRequestId());
        
        return response;
    }

    /**
     * 获取任务状态
     * @param taskId 任务ID
     * @return 任务状态响应
     */
    @GetMapping("/task/{taskId}")
    public StyleGenerationResponse getTaskStatus(@PathVariable String taskId) {
        log.info("查询任务状态: taskId={}", taskId);
        return styleGenerationService.getTaskStatus(taskId);
    }

    /**
     * 等待任务完成
     * @param taskId 任务ID
     * @return 任务完成后的响应
     */
    @GetMapping("/task/{taskId}/wait")
    public StyleGenerationResponse waitForTaskCompletion(@PathVariable String taskId) {
        log.info("等待任务完成: taskId={}", taskId);
        return styleGenerationService.waitForTaskCompletion(taskId);
    }
} 